unit UnidacDM;

interface

uses
  System.SysUtils, System.Classes, Data.DB, MemDS, DBAccess, Uni, UniProvider, AccessUniProvider,
  //ODBCUniProvider,
  IDataHelper,DataCommon, ODBCUniProvider;

type
  TdmUnidac = class(TDataModule,IDataDm)
    acsnprvdr1: TAccessUniProvider;
    con1: TUniConnection;
    unqrySelect: TUniQuery;
    procedure DataModuleCreate(Sender: TObject);
  private
    FIndex:TConnIndex;
  public
    procedure SetIndex(Ix:TConnIndex);
    function  GetIndex:TConnIndex;

    procedure SetQueryText(qrytxt:String);

    function  GetDataSet:TDataSet;overload;
    function  GetDataSet(qrytxt:string):TDataSet;overload;
    function  GetQuery:TUniQuery;

    Property  ConnIndex:TConnIndex read GetIndex write SetIndex;
  end;
function NewDataDm(aOwner:TComponent):IDataDm;
var
  dmUnidac: TdmUnidac;

implementation

{ %CLASSGROUP 'System.Classes.TPersistent' }

{$R *.dfm}
function NewDataDm(aOwner:TComponent):IDataDm;
Begin
  Result := TdmUnidac.Create(aOwner);
End;

procedure TdmUnidac.DataModuleCreate(Sender: TObject);
begin
  with con1 do
  begin
    Connected := False;
    ProviderName := 'Access';
    // Username := '';
    // Password := '';
    // Server := '192.168.82.201';
    Database := ExtractFilePath(ParamStr(0)) + 'dbdemos';
    // Port := 3306;
    Connected := True;
  end;
end;

function TdmUnidac.GetIndex: TConnIndex;
begin
  Result := FIndex;
end;

function TdmUnidac.GetQuery: TUniQuery;
begin
   Result:=unqrySelect;
end;

procedure TdmUnidac.SetIndex(IX: TConnIndex);
begin
  FIndex := IX;
end;

function TdmUnidac.GetDataSet: TDataSet;
begin
  unqrySelect.Active := True;
  Result:=unqrySelect;
end;

function TdmUnidac.GetDataSet(qrytxt: string): TDataSet;
begin
  unqrySelect.SQL.Text := qrytxt;
  unqrySelect.Active := True;
  Result:=unqrySelect;
end;

procedure TdmUnidac.SetQueryText(qrytxt: String);
begin
  unqrySelect.SQL.Text := qrytxt;
  unqrySelect.Active := True;
end;




end.
